package com.app.mapper;

import com.app.model.VoucherRecordModel;
import com.app.vo.RankingVo;
import com.app.vo.VoucherIntegralRecordVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 益联券记录表 Mapper 接口
 * </p>
 *
 * @author 16693103420
 * @since 2024-01-26
 */
@Mapper
public interface VoucherRecordMapper extends BaseMapper<VoucherRecordModel> {
    /**
     * 查询券的记录（根据订单号、名称、手机号、时间范围）
     * @param beginTime
     * @param endTime
     * @param areaId
     * @return
     */
    List<VoucherIntegralRecordVo> getVIntegralRecord(@Param("keyword") String keyword, @Param("beginTime") String beginTime,
                                                     @Param("endTime") String endTime, @Param("pageSize") Integer pageSize,
                                                     @Param("limit") Integer limit, @Param("areaId") Integer areaId,
                                                     @Param("businessId") Integer businessId,@Param("typeName") String typeName);

    /**
     * 查积分的记录（根据订单号、名称、手机号、时间范围）
     * @param beginTime
     * @param endTime
     * @param areaId
     * @return
     */
    List<VoucherIntegralRecordVo>  getVoucherIRecord(@Param("keyword") String keyword, @Param("beginTime") String beginTime,
                                                     @Param("endTime") String endTime, @Param("pageSize") Integer pageSize,
                                                     @Param("limit") Integer limit, @Param("areaId") Integer areaId,
                                                     @Param("businessId") Integer businessId,@Param("typeName") String typeName);

    /**
     * 查积分、券的记录（根据订单号、名称、手机号、时间范围）
     * @param keyword
     * @param beginTime
     * @param endTime
     * @param pageSize
     * @param limit
     * @return
     */
    List<VoucherIntegralRecordVo> VIRecord(@Param("keyword") String keyword, @Param("ifVI") Integer ifVI, @Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("pageSize") Integer pageSize, @Param("limit") Integer limit);

    /**
     * 券的排行榜
     * @return
     */
    List<RankingVo> voucherRanking(@Param("businessId")  Integer businessId,
                                   @Param("cityId")  Integer cityId,
                                   @Param("areaId")  Integer areaId);
/**
 * 券的详情查询（返回数据有用户手机号）
 */
    VoucherRecordModel selectByIdWithPhone(Integer id);

    List<RankingVo> voucherRankingByBusiness(@Param("businessId") Integer businessId);

    BigDecimal voucherRecordStatistics(@Param("keyword") String keyword,
                                       @Param("beginTime") String beginTime,
                                       @Param("endTime")  String endTime,
                                       @Param("areaId") Integer areaId,
                                       @Param("businessId") Integer businessId,
                                       @Param("typeName") String typeName);

    BigDecimal queryAmountCouponsIssuedByType(@Param("beginTime") String beginTime,
                                                      @Param("endTime")  String endTime,
                                                      @Param("title") String  title);
    BigDecimal queryTotalNumberIntegralMall(@Param("beginTime") String beginTime,
                                              @Param("endTime")  String endTime);


    @Select("SELECT  case when SUM(voucher_amount) is null " +
            "        then 0 " +
            "        else SUM(voucher_amount) end totalAmount " +
            " FROM tb_voucher_record " +
            " WHERE user_id = #{userId} AND type_name = #{typeName} ")
    BigDecimal sumVoucherAmountByUserIdAndTypeName(@Param("userId") Integer userId, @Param("typeName") String typeName);


    List<Map<String, Object>> getVoucherInfoList(@Param("roleId") Integer roleId);
}
